<template>
    <div>
        <el-container>
            <el-aside width="15%" style="background: pink">
                <div class="block" style="width: 100px; height: 100px; margin-left: 50px; margin-top: 20px;">
                    <el-upload class="avatar-uploader" action="https://localhost:3000/userImage" :show-file-list="false"
                        :before-upload="beforeAvatarUpload" :on-success="(response, file, fileList) => {
                                return handleSuccess(response, file, fileList);
                            }">
                            
                        <img v-if="imageUrl" :src="file.url" class="avatar">
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                    <p style="font-size: 15px;color: black;">用户：{{ this.user["managerName"] }}</p>
                </div>
                <el-menu default-active="1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
                    @select="changesiderpage" style="margin-top: 30px;border-color: pink;" background-color="pink"
                    text-color="#000" active-text-color="deeppink" active-background-color="lightpink">
                    <el-menu-item index="user">
                        <i class="el-icon-upload"></i>
                        <span slot="title">用户管理</span>
                    </el-menu-item>
                    <el-menu-item index="request">
                        <i class="el-icon-document"></i>
                        <span slot="title">需求列表</span>
                    </el-menu-item>
                    <el-menu-item index="sale">
                        <i class="el-icon-s-data"></i>
                        <span slot="title">出租物品管理</span>
                    </el-menu-item>
                    <el-menu-item index="address">
                        <i class="el-icon-map-location"></i>
                        <span slot="title">地址信息管理</span>
                    </el-menu-item>
                    <el-menu-item index="pinglun">
                        <i class="el-icon-connection"></i>
                        <span slot="title">评论信息管理</span>
                    </el-menu-item>
                </el-menu>
            </el-aside>
            <el-container>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>
  
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 100%;
    min-height: 400px;
}

:active el-menu-vertical-demo.el-menu-item {
    background-color: lightcoral;
}

.djx1 {
    opacity: 0.8;
    background: url("../assets/flied.jpg");
}

.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 50px;
    height: 50px;
    line-height: 50px;
    text-align: center;
}

.avatar {
    width: 50px;
    height: 50px;
    display: block;
}
</style>
  
<script>
export default {
    name: 'Home',
    data() {
        return {
            isCollapse: true,
            fit: 'fill',
            user: {},
            dialogImageUrl: '',
        };
    },
    methods: {
        errorHandler() {
            return true
        },
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        changesiderpage(path) {
            this.$router.push(path)
        },
        // 获取后台存储的用户名，但是读取失败
        // 读取bb={"aa":""}对象用bb["aa"]现在赋值给user的内容就是{"userName":"lzj","pwd":"123","captcha":"6apn"}
        putname() {
            let res1 = localStorage.getItem('user')
            // console.log(res1);
            this.user = JSON.parse(res1);
            // console.log(this.user["userName"]);
        },
        handleAvatarSuccess(res, file) {
            this.imageUrl = URL.createObjectURL(file.raw);
            console.log(this.imageUrl);
        },
        beforeAvatarUpload(file) {
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;
            if (!isJPG) {
                this.$message.error('上传头像图片只能是 JPG 格式!');
            } if (!isLt2M) {
                this.$message.error('上传头像图片大小不能超过 2MB!');
            } return isJPG && isLt2M;
        }
    },
    mounted() {
        this.sidebarItem = this.$route.name;
        this.putname();

    }

};
</script>